var a = require("../../../../@babel/runtime/helpers/toConsumableArray"), t = getApp().globalData.api;

Page({
    data: {
        searchvalue: null,
        listData: [],
        topNum: 0,
        selectChange: "hospital",
        branchDataList: null,
        showBranch: !1
    },
    onLoad: function(a) {
        this.initload(a);
    },
    initload: function(a) {
        var t = this;
        this.setData({
            searchvalue: a.search
        });
        var e = this;
        e.getRequestHospitalList(1).then(function(a) {
            var i = "hospital";
            0 == a.total && e.getRequestPackageList(1).then(function(a) {
                0 != a.total && (i = "package"), e.setData({
                    selectChange: i
                }), console.log(t.data.selectChange);
            });
        });
    },
    searchfocus: function() {
        wx.navigateBack({
            delta: -1
        });
    },
    packageDetailTap: function(a) {
        var t = a.currentTarget.dataset.pkginfo, e = "";
        e = t.hasOwnProperty("sourceId") ? t.hospital.domain + "-combo-" + t.sourceId : t.hospital.domain + "-combo-n" + t.id, 
        wx.navigateTo({
            url: "/pages/packagedetails/packagedetails?requestParams=".concat(e, "&areaCode=").concat(t.hospital.areaCode)
        });
    },
    hospitallink: function(a) {
        var t = a.currentTarget.dataset.hospra, e = t.domain, i = t.areaCode;
        wx.navigateTo({
            url: "/pages/hospitalinfo/hospitalinfo?domain=".concat(e, "&areaCode=").concat(i)
        });
    },
    hospitalDetailTap: function(a) {
        var t = a.currentTarget.dataset.info, e = t.domain, i = t.areaCode;
        wx.navigateTo({
            url: "/pages/hospitalinfo/hospitalinfo?domain=".concat(e, "&areaCode=").concat(i)
        });
    },
    branchTap: function(a) {
        this.closeBranchTap();
        var t = "/pages/hospitalinfo/hospitalinfo?domain=".concat(a.currentTarget.dataset.info.domain, "&areaCode=").concat(a.currentTarget.dataset.info.areaCode);
        wx.navigateTo({
            url: t
        });
    },
    closeBranchTap: function() {
        this.setData({
            showBranch: !1
        });
    },
    getRequestHospitalList: function(e) {
        var i = this, o = {
            pageNum: e,
            pageSize: 10,
            searchModel: {
                areaCode: getApp().globalData.selectedCityAreaCode,
                clientType: 2,
                lat: getApp().globalData.localLatitude || "",
                lon: getApp().globalData.localLongitude || "",
                oriFutureDate: "",
                name: this.data.searchvalue,
                originUnitParam: "",
                oriOrderBy: ""
            }
        };
        return t.postPort("hospitalList", o).then(function(t) {
            if ("SUCCESS" == t.result) {
                var e = i.data.listData;
                return 1 == t.values.pageNum ? (i.goTop(), e = t.values) : (e.list = [].concat(a(i.data.listData.list), a(t.values.list)), 
                e.pageNum = t.values.pageNum, e.total = t.values.total, e.microBottomCriteriaListDTOS = t.values.microBottomCriteriaListDTOS, 
                e.microCriteriaListDTOS = t.values.microCriteriaListDTOS), i.setData({
                    loadingExit: e.list.length >= t.values.total,
                    listData: e,
                    values: t.values
                }), e;
            }
        }, function(a) {});
    },
    scrollLoading: t.throttle(function(a) {
        a.loadMoreData();
    }, 800),
    loadMoreData: function() {
        this.data.loadingExit || ("package" == this.data.selectChange ? this.getRequestPackageList(this.data.listData.pageNum + 1) : "hospital" == this.data.selectChange && this.getRequestHospitalList(this.data.listData.pageNum + 1));
    },
    changtab: function(a) {
        var t = a.currentTarget.dataset.tab;
        t != this.data.selectChange && ("hospital" == t ? this.getRequestHospitalList(1) : "package" == t && this.getRequestPackageList(1), 
        this.goTop(), this.setData({
            selectChange: t
        }));
    },
    goTop: function() {
        this.setData({
            topNum: 0
        });
    },
    hospitalBranchTap: function(a) {
        var t = a.currentTarget.dataset.info;
        this.getHospitalBranchDat(t.areaCode, t.groupId, t.id);
    },
    getHospitalBranchDat: function(a, e, i) {
        if (a || e) {
            var o = this, s = {
                pageNum: 1,
                pageSize: 50,
                searchModel: {
                    areaCode: a,
                    name: null,
                    hospitalGroupId: e
                }
            };
            t.postPort("listMicroBrandHospitalList", s, !1).then(function(a) {
                if ("SUCCESS" == a.result) {
                    var t = [];
                    a.values.list.forEach(function(a, e) {
                        a.id != i && t.push(a);
                    }), o.setData({
                        branchDataList: t,
                        showBranch: !0
                    });
                }
            }, function(a) {
                a.data.hasOwnProperty("result") && "ERROR" == a.data.result && wx.showToast({
                    title: a.data.message[0].message,
                    icon: "none",
                    duration: 2e3,
                    mask: !0
                });
            });
        }
    },
    getRequestPackageList: function(e) {
        var i = this, o = {
            pageNum: e,
            pageSize: 10,
            areaCode: getApp().globalData.selectedCityAreaCode,
            name: this.data.searchvalue
        };
        return t.postPort("comboList", o, !i.data.values).then(function(t) {
            if ("SUCCESS" == t.result) {
                var e = i.data.listData;
                return 1 == t.values.pageNum ? (i.goTop(), e = t.values) : (e.list = [].concat(a(i.data.listData.list), a(t.values.list)), 
                e.pageNum = t.values.pageNum, e.total = t.values.total, e.microBottomCriteriaListDTOS = t.values.microBottomCriteriaListDTOS, 
                e.microCriteriaListDTOS = t.values.microCriteriaListDTOS), i.setData({
                    loadingExit: e.list.length >= t.values.total,
                    listData: e,
                    values: t.values
                }), e;
            }
        }, function(a) {});
    },
    onReady: function(a) {
        console.log(a);
    },
    onShow: function() {},
    onHide: function() {},
    onUnload: function() {},
    onPullDownRefresh: function() {},
    onReachBottom: function() {},
    onShareAppMessage: function() {}
});